package com.yang;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

public final class YangRandomTransfer extends JavaPlugin {
    private static FileConfiguration config;
    @Override
    public void onEnable() {
        this.saveDefaultConfig();
        config = this.getConfig();
        Bukkit.getPluginCommand("yangRandomTransfer").setExecutor(this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!label.equalsIgnoreCase("yangRandomTransfer")){
            sender.sendMessage("指令错误哦~");
            return true;
        }
        if (!(sender instanceof Player)) {
            sender.sendMessage(ChatColor.YELLOW + "你不是玩家哦~");
            return true;
        }
        Player player = (Player) sender;
        int x = (int) (Math.random() * 10000);
        int z = (int) (Math.random() * 10000);
        int y = player.getWorld().getHighestBlockYAt(x, z);
        player.teleport(player.getWorld().getSpawnLocation().add(x, y, z));
        player.setAllowFlight(false);
        return true;
    }

    @Override
    public void onDisable() {
    }
}
